var express = require("express");
var router = express.Router();
const typeTwoApi = require("../api/typeTwo");

//获取
router.get("/", async function (req, res, next) {
  const data = await typeTwoApi.get(req.query);
  res.send(data);
});

router.get("/typeOne=:typeOneId", async function (req, res, next) {
  const data = await typeTwoApi.getFromTypeOneId(req.params.typeOneId);
  res.send(data);
});

//搜索品牌
router.post("/search", async function (req, res, next) {
  const { listQuery, page, limit } = req.body;
  const { typeTwo, typeOneId } = listQuery;
  const data = await typeTwoApi.search({ typeTwo, typeOneId, page, limit });
  res.send(data);
});
//添加
router.post("/", async function (req, res, next) {
  const data = await typeTwoApi.add(req.body);
  res.send(data);
});
//通过类型搜索
router.post("/search/:_id", async function (req, res, next) {
  const { _id } = req.params;
  const data = await typeTwoApi.searchId({ _id });
  res.send(data);
});
//修改
router.put("/upDate/:_id", async function (req, res, next) {
  const { _id } = req.params;
  const typeTwo = req.body;
  const data = await typeTwoApi.upDateOne({ _id, typeTwo });
  res.send(data);
});

//删除
router.delete("/del/:_id", async function (req, res, next) {
  const { _id } = req.params;
  console.log(_id);
  const data = await typeTwoApi.delOne({ _id });
  res.send(data);
});

module.exports = router;
